﻿
CREATE PROCEDURE [dbo].[fares_ExistaLocalitate]
	-- Add the parameters for the stored procedure here
	@nume varchar(50), 
	@idjudet int,
	@idloc int out
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @idJ int;
	IF NOT EXISTS(SELECT * FROM [Judete] WHERE [IDJudet]=@idjudet)
		set @idloc=-1
    -- Insert statements for procedure here
	SELECT @idloc = [IDLocalitate] from [Localitati] WHERE UPPER(Nume) like UPPER(@nume) + '%' AND [IDJudet]=@idjudet
	IF @idloc is null
	begin
		INSERT INTO [Localitati]
           ([Nume],[CodPostal],[IDJudet],[PrefixTelefonic])
		VALUES
           (@nume,'00000',@idJudet,'00000')
		SELECT @idloc = @@IDENTITY
	end
END